package bgate.hung.workerclass;

import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Typeface;

public class Player {
	public static final int MALE = 0;
	public static final int FEMALE = 1;
	public static final int MAX_ACC_LENGTH = 10;
	public static final int BOSS = 2;
	public static final int READY = 1;
	public static final int WAITTING = 0;
	public static final int POSITION_12H = 0;
	public static final int POSITION_3H = 1;
	public static final int POSITION_6H = 2;
	public static final int POSITION_9H = 3;
	public static final int MOM = 4;
	public static final int DEN_LANG = 5;
	public static final int U = 6;
	public static final int U_DEN = 7;
	public static final int THANG = 0;

	private Bitmap avatar;
	private Bitmap boss;
	private Bitmap ready;
	private String acc;
	private String acc_display;
	private String money;
	private int x;
	private int y;
	private int state;
	private Paint textPaint1;
	private Paint textPaint2;
	private Paint textPaint3;
	public boolean isMe = false;
	public boolean isHiden = false;
	public boolean drawState = true;
	private int position;
	private int countCardAn = 0;
	private int sttBiAn = 10;
	private int ketqua;
	private int totalMoneyEffect = 0;
	private int moneyEffect = 0;
	public boolean draw_effect = false;
	private int width;

	public Player(String acc, int money, int state) {
		this.acc = acc;
		this.acc_display = checkAccLength(acc);
		this.money = Integer.toString(money);
		this.state = state;

		textPaint1 = new Paint();
		textPaint1.setColor(Color.rgb(250, 150, 0));
		textPaint1.setTextSize(15);
		textPaint1.setTypeface(Typeface.create("Arial", Typeface.BOLD));
		textPaint2 = new Paint();
		textPaint2.setColor(Color.RED);
		textPaint2.setTextSize(12);
		textPaint2.setTypeface(Typeface.create("Arial", Typeface.BOLD));
		textPaint3 = new Paint();
		textPaint3.setTextSize(12);
		textPaint3.setColor(Color.WHITE);

		avatar = StaticBitmap.getBoyAvatarImage();
		boss = StaticBitmap.getBossImage();
		ready = StaticBitmap.getReadyPlayImage();
	}

	public void reset() {
		drawState = true;
		countCardAn = 0;
		sttBiAn = 10;
		totalMoneyEffect = 0;
		moneyEffect = 0;
		draw_effect = false;
	}

	public void draw(Canvas canvas) {
		canvas.drawBitmap(avatar, x, y, null);
		if (drawState)
			if (state == BOSS)
				canvas.drawBitmap(boss, x, y - boss.getHeight() + 10, null);
			else if (state == READY) {
				if (position == POSITION_6H)
					canvas.drawBitmap(ready, x, y - ready.getHeight(), null);
				else if (position == POSITION_3H)
					canvas.drawBitmap(ready, x, y - ready.getHeight(), null);
				else if (position == POSITION_12H)
					canvas.drawBitmap(ready, x, y + avatar.getHeight(), null);
				else if (position == POSITION_9H)
					canvas.drawBitmap(ready, x, y - ready.getHeight(), null);
			}

		if (position == POSITION_6H || position == POSITION_12H)
			canvas.drawText(acc_display, x + avatar.getWidth(),
					y + 2 *avatar.getWidth() / 3, textPaint1);
		else
			canvas.drawText(acc_display, x, y + avatar.getHeight() + 15, textPaint1);

		if (position == POSITION_6H || position == POSITION_12H)
			canvas.drawText(money, x + avatar.getWidth(), y + 2 * avatar.getWidth()
					/ 3 + 15, textPaint3);
		else
			canvas.drawText(money, x, y + avatar.getHeight() + 30, textPaint3);
	}

	private String checkAccLength(String acc) {
		String result = acc;
		if (acc.length() > MAX_ACC_LENGTH) {
			String temp = "";
			for (int i = 0; i < MAX_ACC_LENGTH + 1; i++) {
				temp += acc.charAt(i);
			}
			result = temp + "..";
		}
		return result;
	}

	public void setState(int s) {
		state = s;
	}

	public int getState() {
		return state;
	}

	public void setKetQua(int t) {
		ketqua = t;
	}

	public int getKetQua() {
		return ketqua;
	}

	public void setMoneyEffect(int m) {
		moneyEffect = m;
		totalMoneyEffect += moneyEffect;
	}

	public int getMoneyEffect() {
		return moneyEffect;
	}

	public int getTotalMoneyEffect() {
		return totalMoneyEffect;
	}

	public String getAccount() {
		return acc;
	}

	public String getAccDisplay() {
		return acc_display;
	}

	public void setX(int x) {
		this.x = x;
	}

	public void setY(int y) {
		this.y = y;
	}
	
	public int getX() {
		return this.x;
	}
	
	public int getY() {
		return this.y;
	}

	public void setAccount(String acc) {
		this.acc = acc;
		this.acc_display = checkAccLength(acc);
	}

	public void setAccDisplay(String acc) {
		this.acc_display = acc;
		width = (int) (avatar.getWidth() + textPaint1.measureText(acc_display));
	}

	public void setAnBai(int s) {
		if (sttBiAn == s) {
			countCardAn++;
		} else {
			sttBiAn = s;
			countCardAn = 1;
		}
	}

	public boolean checkUDen() {
		if (countCardAn == 3)
			return true;
		else
			return false;
	}

	public void setMoney(int money) {
		this.money = Integer.toString(money);
	}

	public int getMoney() {
		return (Integer.valueOf(money));
	}

	public int getWidth() {
		return this.width;
	}

	public int getHeight() {
		return this.avatar.getHeight();
	}

	// public void drawPlay(Canvas canvas) {
	// // draw avatar
	// canvas.drawBitmap(bitmap, x, y, null);
	//
	// // account
	// canvas.drawText(acc_display, x + 3 + bitmap.getWidth(), y + 10,
	// textPaint1);
	//
	// }

	public void setPositon(int p) {
		this.position = p;
	}

	public int getPosition() {
		return this.position;
	}
}
